global root_dir = "`1'"

include "$root_dir/code/config/config.do"


cap noi log using ${log_dir}/import_exchange_xeu_iep.log, replace name(dat)

*Handle empty arguments
global arg1 = cond("`2'" == "___EMPTY___", "", "`2'")
global arg2 = cond("`3'" == "___EMPTY___", "", "`3'")
global arg3 = cond("`4'" == "___EMPTY___", "", "`4'")
global arg4 = cond("`5'" == "___EMPTY___", "", "`5'")

if "$arg1" != "" {
    global weight_category "$arg1"
    di "Weight category: ${weight_category}"
}

if "$arg2" != "" {
    global weight_versions "$arg2"
    di "Weight versions: ${weight_versions}"
}

if "$arg3" != "" {
    global weight_window "$arg3"
    di "Weight window: ${weight_window}"
}

if "$arg4" != "" {
	global wtype "$arg4"
}
di "${wtype}"
capture noi {

*Here we import the exchange rates for the Irish Punt (IEP) to the European Currency Unit (XEU) from 1979 to 1988 and generate a mean exchange rate for each year.
*IEP to XEU conversion rates | Irish Central Bank | https://www.centralbank.ie/statistics/interest-rates-exchange-rates/exchange-rates | downloaded December 14th 2023
import excel using ${mow_data_raw}\exchange_rates\ieprates-1979-1988.xls, clear firstrow

* a bit of cleaning
keep Date XEU
gen year = year(Date)
*excel file has a weird empty field 
drop if year == .

*construct the exchange rate average
collapse (mean) XEU, by(year)
replace XEU = 1/XEU
save ${mow_data_proc}/ieprates.dta, replace


}
if _rc == 0 {
    display "Execution finished successfully."
}
else {
    display "Execution finished with errors."
}

cap log close dat